<template>
  <div>
    
    <el-card class="w3">
      <div class="myChart" ref="myChartDom"></div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from "echarts";
import {GetTo}from "@/http/api";

export default {
  
  name: "report",
  data() {
    return {
      preChartData: {
        title: {
          text: "用户来源",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#E9EEF3",
            },
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            boundaryGap: false,
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
      },
    };
  },
  mounted() {
    this.loadChart();
  },
  methods: {
    async loadChart() {
      const myChartDom = this.$refs.myChartDom;
      const chart = echarts.init(myChartDom);
      const res = await GetTo();
      const mergeData = { ...this.preChartData, ...res };

      const options = mergeData;
      chart.setOption(options);
      window.addEventListener("resize", function () {
        chart.resize();
      });
    },
  },
};
</script>
<style scoped lang='scss'>
.myChart {
  width: 100%;
  height: 420px;
  border: 1px solid #ccc;
}
.w3{
    margin-top: 20px;
}
</style>
